<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>

<body>
<form class="layui-form">
    <div class="layui-form">

        <div class="layui-form-item">
            <label class="layui-form-label">产品型号</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" name="productType" placeholder="请输入型号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">故障描述</label>
            <div class="layui-input-block">
                <input type="text"lay-verify="required" name="orderDescription" placeholder="请简述故障" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">优先级</label>
            <div class="layui-col-md2">
                <select name="orderPriority">
                    <option value="">请选择</option>
                    <option value=0>正常</option>
                    <option value=1>较高</option>
                    <option value=2>高</option>
                    <option value=3>非常高</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联系人姓名</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required" name="orderClientname" placeholder="请输入联系人姓名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">联系人</label>
            <div class="layui-input-block">
                <input type="text" lay-verify="required|phone" name="orderClientphone" placeholder="请输入联系人手机号" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item" id="area-picker">
            <div class="layui-form-label">居住地址</div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="orderProvince" lay-verify="required" class="province-selector" data-value="天津市" lay-filter="province-1">
                    <option value="">请选择省</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="orderCity"lay-verify="required" class="city-selector" data-value="天津市" lay-filter="city-1">
                    <option value="">请选择市</option>
                </select>
            </div>
            <div class="layui-input-inline" style="width: 200px;">
                <select name="orderArea" lay-verify="required" class="county-selector" data-value="西青区" lay-filter="county-1">
                    <option value="">请选择区</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">详细地址</label>
            <div class="layui-input-block">
                <input type="text"lay-verify="required" name="orderAddress" placeholder="详细地址" autocomplete="off" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">上门日期</label>
            <div class="layui-input-block">
                <input id="orderDate" type="text" lay-verify="required" name="orderDate" placeholder="请选择日期" autocomplete="off" class="layui-input" id="appointmentDate">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">时间段</label>
            <div class="layui-col-md2">
                <select name="orderTime">
                    <option value="">请选择</option>
                    <option value=0>上午</option>
                    <option value=1>下午</option>
                    <option value=2>晚上</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="submitBtn1">提交</button>
            </div>
        </div>
    </div>

</form>
</body>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../../js/axios.min.js"></script>
<script>
    layui.use(['layer', 'form', 'layarea','laydate'], function () {
        var layarea = layui.layarea;
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        // 初始化日期选择器

            laydate.render({
                elem: '#orderDate', // 绑定日期选择器的 ID
                type: 'date' // 设置日期选择的类型为年月日
                // 其他配置项，根据需要进行设置
            });



        layarea.render({
            elem: '#area-picker',

            change: function (res) {
                //选择结果
                console.log(res);
            }
        });


        form.on('submit(submitBtn1)', function (data) {
            event.preventDefault();

            data = data.field;
            console.log(data)
            var formDataObj = new FormData();

            for (var key in data) {
                formDataObj.append(key, data[key]);

            }


            console.log(formDataObj)
            axios.post('http://localhost:8080/order/admit', formDataObj,{
                withCredentials: true
            })
                .then(function(response) {
                    // 请求成功的处理逻辑
                    console.log(response)
                    layer.msg('申请提交成功', {time: 300}, function() {
                        // 关闭表单弹出层
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                        location.reload()
                    });
                })
                .catch(function(error) {
                    // 请求失败的处理逻辑
                    console.error(error);
                });

        });

    });
</script>
</html>